<template>
  <div class="lg-container" v-wechat-title="$route.meta.title">
    <div class="info-head">
      <img v-if="doctorInfo.avatar" :src="doctorInfo.avatar" alt />
      <img v-if="!doctorInfo.avatar && !doctorInfo.sex" src="@/assets/doctor_man.jpg" alt />
      <img v-if="!doctorInfo.avatar && doctorInfo.sex" src="@/assets/doctor_woman.jpg" alt />
      <div class="details">
        <div class="info-name">
          <span class="doctor-name">{{ doctorInfo.nick || '暂无姓名'}}</span>
          <span class="doctor-technical">{{ doctorInfo.doctor.professionCallShow || '暂无职称' }}</span>
        </div>
        <div class="info-type">
          <span class="doctor-type">{{ doctorInfo.doctor.department || '暂无科室' }}</span>
          <span class="doctor-hospital">{{ doctorInfo.doctor.doctorHospital || '暂无医院' }}</span>
        </div>
      </div>
    </div>
    <div class="info-content">
      <div class="info-item">
        <h5>我的简介</h5>
        <div class="info-con">{{doctorInfo.doctor.introduction || '暂无简介'}}</div>
      </div>
      <div class="info-item">
        <h5>擅长手术</h5>
        <div class="info-con">{{doctorInfo.doctor.operation || '暂无擅长手术'}}</div>
      </div>
      <div class="info-item">
        <h5>擅长疾病</h5>
        <div class="info-con">{{doctorInfo.doctor.disease || '暂无擅长疾病'}} </div>
      </div>
      <div class="info-item">
        <h5>荣誉证书</h5>
        <div class="info-con">
          <div v-if="doctorInfo.doctor.honorCertificates.length === 0" class="certificate-null"><span>暂无荣誉证书</span></div>
          <div v-else class="certificate-item" v-for="(item, index) in doctorInfo.doctor.honorCertificates" :key="index">
            <img :src="item" alt="">
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { doctorInfo } from '@/api/info'
export default {
  data () {
    return {
      doctorInfo: {
        doctor: {
          honorCertificates: []
        }
      },
      openId: null
    }
  },
  mounted () {
    if (this.$route.query.openId) {
      this.openId = this.$route.query.openId
      this.getInfo()
    }
  },
  methods: {
    getInfo () {
      this.$toast.loading({
        message: '加载中...',
        forbidClick: true,
        overlay: true,
        duration: 0
      })
      doctorInfo(this.openId).then(res => {
        this.$toast.clear()
        if (res.code === 200) {
          switch (res.status) {
            case '1':
              this.$dialog.confirm({
                title: '提示',
                message: '暂未绑定医生，请前往绑定',
                showCancelButton: false,
                confirmButtonColor: '#03A9AC'
              }).then(() => {
                this.$router.push('/infoBound?openId=' + this.openId)
              }).catch(() => {
              })
              break
            case '2':
              setTimeout(() => {
                this.$router.push('/establishStatus?openId=' + this.openId)
              }, 1000)
              break
            case '3':
              this.doctorInfo = res.data.info
              this.doctorInfo.doctor.honorCertificates = this.doctorInfo.doctor.honorCertificates ? this.doctorInfo.doctor.honorCertificates.split(',') : []
              break
            default:
              this.doctorInfo = res.info
              this.doctorInfo.doctor.honorCertificates = this.doctorInfo.doctor.honorCertificates ? this.doctorInfo.doctor.honorCertificates.split(',') : []
              break
          }
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.lg-container {
  width: 100%;
  background-color: #EDEEEF;
  min-height: 100vh;
  .info-head {
    height: 90px;
    width: 100%;
    background-color: #fff;
    display: flex;
    align-items: center;
    padding: 0 20px;
    box-sizing: border-box;
    img {
      width: 60px;
      height: 60px;
      border-radius: 50%;
      border: 1px solid #DCDCDC;
    }
    .details {
      margin-left: 10px;
      .info-name {
        .doctor-name {
          color: #333333;
          font-size: 15px;
          margin-right: 8px;
        }
        .doctor-technical {
          color: #333333;
          font-size: 12px;
        }
      }
      .info-type {
        margin-top: 3px;
        .doctor-type {
          color: #888888;
          font-size: 12px;
          margin-right: 8px;
        }
        .doctor-hospital {
          color: #888888;
          font-size: 12px;
        }
      }
    }
  }
  .info-content {
    background-color: #fff;
    margin: 10px 0 0;
    .info-item {
      width: 100%;
      border-bottom: 1px solid #EDEEEF;
      padding: 15px 20px;
      box-sizing: border-box;
      h5 {
        margin: 0 0 10px;
        color: #333333;
        font-size: 13px;
      }
      .info-con {
        color: #888888;
        font-size: 12px;
        line-height: 18px;
        .certificate-item {
          width: 70px;
          height: 70px;
          border-radius: 5px;
          margin: 0 18px 18px 0;
          overflow: hidden;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }
    }
  }
}
</style>
